package cn.mumzone.pos.ui.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioButton;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.mumzone.basic.adapter.rv.CommonAdapter;
import cn.mumzone.basic.adapter.rv.ViewHolder;
import cn.mumzone.basic.util.ListUtil;
import cn.mumzone.basic.util.StringUtils;
import cn.mumzone.pos.R;
import cn.mumzone.pos.model.ScheduleEmployeeEntity;

/**
 * Created by qiuzhenhuan on 2019/7/10.
 */


public class ADA_ScheduleEmployee extends CommonAdapter<ScheduleEmployeeEntity> {


    private boolean hasAddButton = false;

    private OnItemClickListener onItemClickListener;

    public ADA_ScheduleEmployee(Context context) {
        super(context);
        this.mContext = context;
    }

    @Override
    protected int itemLayoutId() {
        return R.layout.view_schedule_employee;
    }

    @Override
    protected void convert(final ViewHolder holder, ScheduleEmployeeEntity scheduleEmployeeEntity, final int position) {


    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        final ScheduleEmployeeEntity entity;

        holder.setVisible(R.id.iv_add, hasAddButton && position == 0);
        holder.setVisible(R.id.tv_employee_title, hasAddButton && position == 0);

        holder.setVisible(R.id.iv_icon, !hasAddButton || position != 0);
        holder.setVisible(R.id.tv_employee, !hasAddButton || position != 0);

        holder.setBackgroundRes(R.id.ll_root, hasAddButton && position == 0 ?
                R.drawable.shape_bg_white_with_black_stroke : R.drawable.bg_shape_bg_color_with_corners);

        if (hasAddButton) {

            if (position == 0) {
                entity = null;
            } else {
                entity = getDataList().get(position - 1);
                holder.setText(R.id.tv_employee, StringUtils.getUserName(entity.getEmployeeName()));
            }
        } else {
            entity = getDataList().get(position);
            holder.setText(R.id.tv_employee, StringUtils.getUserName(entity.getEmployeeName()));
        }
        holder.getConvertView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onItemClickListener != null) {
                    onItemClickListener.onItemClick(entity, position);
                }
            }
        });
    }

    @Override
    protected boolean useItemViewDelegateManager() {
        return false;
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    @Override
    public int getItemCount() {
        if (hasAddButton) {
            return ListUtil.isListEmpty(getDataList()) ? 1 : getDataList().size() + 1;
        } else {
            return ListUtil.isListEmpty(getDataList()) ? 0 : getDataList().size();
        }
    }

    public void setHasAddButton(boolean hasAddButton) {
        this.hasAddButton = hasAddButton;
    }

    public interface OnItemClickListener {

        void onItemClick(ScheduleEmployeeEntity employeeEntity, int position);
    }

}
